package utils;

import com.issac.vhr.entity.Hr;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class HrUtils {
    public static Hr currentHr = null;
    public static Hr getCurrentHr(){
          currentHr =  ((Hr) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
          return currentHr;
    }
    public static void updateCurrentHr(Hr hr,Authentication authentication){
        SecurityContextHolder.getContext().
                setAuthentication(new UsernamePasswordAuthenticationToken(hr,authentication.getCredentials(),authentication.getAuthorities()));
    }
}
